package com.nuonuo.controller;

import com.alibaba.fastjson2.JSONObject;
import com.nuonuo.config.RedisUtils;
import com.nuonuo.config.RedissonUtils;
import com.nuonuo.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author duan
 * @version 1.0
 * @date 2023/10/24 19:22
 */
@RestController
@RequestMapping
public class HelloController {
    @Resource
    protected RedisUtils redisUtils;

    @GetMapping(value = "sayHello")
    public String sayHello() {
        return "hello, world";
    }

    @GetMapping(value = "setRedis")
    public String setRedis(String key) {
        String value = "{\"account\":\"18758277487\",\"authId\":\"2b79fde0a3424c41b0e01752965c0ad8\",\"indAuthQrParam\":false,\"queueKey\":\"2b79fde0a3424c41b0e01752965c0ad8\",\"queueName\":\"elin:delay:qr:code\",\"retryNum\":1,\"sellerTaxnum\":\"92360822MA7BGDPD80\",\"taxNum\":\"92360822MA7BGDPD80\"}";
        JSONObject jsonObject = JSONObject.parseObject(value);
        jsonObject.put("sellerTaxnum", "150301199811285326");
        jsonObject.put("taxNum", "1111222233334444");
        redisUtils.zadd(key, jsonObject.toJSONString(), DateUtil.offsetSecond(new Date(), 15).getTime());
        return "OK";
    }

    @GetMapping(value = "setNumRedis")
    public String setRedis(int num) {
        for (int i = 1; i <= num; i++) {
            setRedis("elin:delay:qr:code:" + i);
        }
        return "OK";
    }

    @GetMapping(value = "setNumSecondsRedis")
    public void setRedis(int num, int seconds) {
        setRedis(num);
        while(true) {
            try {
                Thread.sleep(seconds * 1000);
            } catch (Exception e) {
                e.printStackTrace();

            }
        }
    }
}
